package cate.game.role.show.msg;

import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBBlog;
import cate.game.role.Role;
import cate.game.role.show.icon.HeadIconVO;
import easy.java.dev.note.NoteField;
import easy.java.practice.errorcode.EcResult;

@ClientMsg(title = "修改头像 の 请求")
public class ModifyHeadIconReq implements MsgInput {

    @NoteField("头像id")
    public int tid;

    @Override
    public void execute(GameBody game, ClientContext cc) {
       EcResult r =  settle(cc.getRole(),tid);
       game.notice.message(cc.getRole(), r, true);
    }

    private EcResult settle(Role role, int tid) {
        EcResult r = new EcResult();
        boolean active = role.getShow().headIcon.isActive(tid);
        if (!active) {
            return r.fail("头像未激活");
        }
        role.getBase().headIcon = new HeadIconVO(tid);
        role.send(new ModifyHeadIconResp(role));
        role.getGame().notice.message(role, "修改成功");
        return r.success();
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBBlog.MODIFY_HEAD_ICON_REQ;
    }
}
